import { createApp, ref } from 'vue'
import ElementPlus from 'element-plus'
import App from './App.vue'
// import store from '@/store/index.js'
import 'dayjs/locale/zh-cn';
import 'element-plus/lib/theme-chalk/index.css';
import './style/index.styl'
import enLocale from 'element-plus/lib/locale/lang/en';
import zhLocale from "element-plus/lib/locale/lang/zh-cn";
import store from '@/store';
import router from '@/router'
// import i18n from './i18n/index'
// import 'xe-utils'
// import VXETable from 'vxe-table'
// import 'vxe-table/lib/style.css'

// debugger
ElementPlus.useLang = (app, ref, locale) => {
    const template = (str, option) => {

        if (!str || !option) return str
        return str.replace(/\{(\w+)\}/g, (_, key) => {
            // console.log(option[key])

            return option[key]
        })
    }

    // 注入全局属性,子组件都能通过inject获取
    // console.log(arguments)
    app.provide('ElLocaleInjection', {
        lang: ref(locale.name),
        locale: ref(locale),
        t: (...args) => {
            // debugger

            // console.log(args)
            const [path, option] = args
            // console.log(path)

            let value
            const array = path.split('.')
            let current = locale
            for (let i = 0, j = array.length; i < j; i++) {
                // debugger
                const property = array[i]
                value = current[property]
                if (i === j - 1) return template(value, option)
                if (!value) return ''
                current = value
            }
        },
    })
}

const app = createApp(App)
// app.use(VXETable)
ElementPlus.useLang(app, ref, zhLocale)
// ElementPlus.useLang(app, ref, zhLocale)

// app.use(i18n)
app.use(store).use(router).use(ElementPlus).mount('#app')

// app


// debugger
